Page({

    data: {
      timu:[],
      answer:[],
      photo:[],
      score:0,
    },
    user_input(e){
      this.data.answer[e.target.dataset.id]=e.detail.value
      this.setData({
        answer:this.data.answer
      })
    },
    submit(){
            var score = 0
            for(var i =0;i<10;i++){
              if(this.data.timu[i].C == parseInt(this.data.answer[i])){
                this.data.photo.splice(i,1,"/images/week8/smile.png")
                score = score+10
                this.setData({
                  photo:this.data.photo,
                  score:score
                })
              }else{
                this.data.photo.splice(i,1,"/images/week8/sad.png")
                this.setData({
                  photo:this.data.photo
                })
              }
            }
            wx.showToast({
              title: '你的得分是'+this.data.score+"分",
            })
    },
    clean(){
        wx.showLoading({
          title: '正在重新出题...',
          mask:true,
          success:res=>{
            this.setData({
                score:0,
                timu:[],
                photo:[]
            })
            this.onLoad()
          }
        })
        setTimeout(function () {
            wx.hideLoading()
          }, 300)

    },
    onLoad(options) {
      for(var i = 0;i<10;i++){
        var A = parseInt(Math.random()*100)
        var B = parseInt(Math.random()*100)
        var C = A + B
        this.data.timu.push(
          {A:A,B:B,C:C}
        )
      }
      this.setData({
        timu:this.data.timu
      })
    },
})